﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLNHASACH.PresentationLayer.SearchCtrl.Sach
{
    public partial class ListBoxSach : UserControl
    {
        public ListBoxSach()
        {
            InitializeComponent();
        }
        public delegate void sukien();
        public event sukien ItemClick;

        public ItemSach SelectedItem=new ItemSach();

        public List<ItemSach> Items=new List<ItemSach>();
        private DataTable _datasource;
        public DataTable Datasource
        {
            set
            {
                _datasource = value;
                foreach (DataRow row in _datasource.Rows)
                {
                    ItemSach item=new ItemSach();
                    item.Clik += new ItemSach.sukien(item_Clik);
                    item.SetData(row);
                    this.Controls.Add(item);
                    item.Dock = DockStyle.Top;
                    Items.Add(item);
                }
            }
        }

        void item_Clik(object sender)
        {
            SelectedItem = (ItemSach)sender;
            if (ItemClick != null)
                ItemClick();
        }
    }
}
